package top.hcode.hoj.utils;

import org.nutz.http.Http;
import org.nutz.http.Response;
import org.nutz.lang.Files;

/**
 * @author orangej
 * @since 2024/12/31
 */
public class HttpUtils {

    public static String downloadFileContent(String url) {
        Response response = Http.get(url, 6000);
        if (response.isOK()) {
            return response.getContent();
        }

        throw new RuntimeException("下载文件失败 status:" + response.getStatus() + " content:" + response.getContent());
    }

    public static void downloadFile(String url, String path) {
        Response response = Http.get(url, 6000);
        if (response.isOK()) {
            Files.write(path, response.getStream());
            return ;
        }

        throw new RuntimeException("下载文件失败 status:" + response.getStatus() + " content:" + response.getContent());
    }
}
